import { ref } from "vue";
import { defineStore } from "pinia";
import { getSystyemModules } from "@/mctp-api/global";
// import type { ModuleItem } from "@/mctp-api/global/index.d";

interface ModuleItem {
  name: string;
  moduleKey: string;
  folder: string;
  fileName: string;
  loadExternalModules: boolean;
}

export const useGlobalModulesStore = defineStore("globalModules", () => {
  // 存储系统模块列表
  const systemModules = ref<ModuleItem[]>([]);

  /**
   * @description: 读取系统配置
   * @return {Promise<ModuleItem[]>} 返回模块列表
   */
  const loadSystemModules = async (): Promise<ModuleItem[]> => {

    const response = await fetch('/load-modules-config.json');

    if (!response.ok) {
      console.error('模块配置加载失败:', response.status);
      systemModules.value = [];
      return [];
    }

    const config = await response.json();
    systemModules.value = config?.modules || [];
    console.log("systemModules.value", systemModules.value);
    return systemModules.value;
  };

  return {
    systemModules,
    loadSystemModules,
  };
});

